#!/usr/bin/python3
# -*- coding: utf-8 -*-
import pandas as pd
import numpy as np

eps = 1e-8

def signal(*args):
    # Hma
    df = args[0]
    n = args[1]
    factor_name = args[2]

    '''
    N=20 
    HMA=MA(HIGH,N)
    HMA 指标为简单移动平均线把收盘价替换为最高价。
    当最高价上穿/下穿 HMA 时产生买入/卖出信号
    '''
    hma = df['high'].rolling(n, min_periods=1).mean()
    # 剔除量纲
    df[factor_name] = (df['high'] - hma) / (hma + eps)

    return df
